home *** CD-ROM | disk | FTP | other *** search
- /*
- Alloy File Restoral Program
- V4.42 02/07/84 by Kyle Powell and Mark Hurst
- V4.51 04/18/84
-
- For use with NetWare V4.n
-
- Copyright (C) 1983, 1984 Novell, Inc.
- */
-
- #include "ctype.h"
- #include "stdio.h"
-
-
- #define LOCALBIT 0x80
- #define PERMNET 0x01
- #define TEMPNET 0x02
- #define NETBITS 0x03
-
- #define READBIT 0x01
- #define WRITEBIT 0x02
- #define OPENBIT 0x04
- #define CREATEBIT 0x08
- #define DELETEBIT 0x10
- #define OWNEDBIT 0x20
- #define SEARCHBIT 0x40
- #define MODIFYBIT 0x80
-
- /* NOTE: the Archive bit was 0x80 on ShareNet V3.12. Has now changed: */
- #define BACKUPBIT 0x20
- #define LASTBIT 0x10
-
- extern unsigned DOS11, DOS20;
- unsigned unitsize;
- unsigned fileswritten;
- unsigned restorerights;
-
- #define VARPATH '^' - 'A'
-
- #define TRUE 1
- #define FALSE 0
-
- #define MAXVOLUMES 16
- #define MAXSPECS 100
-
- #define ALLMODE 1
- #define MODMODE 2
- #define SELMODE 3
-
-
- FILE *log;
- int source, target; /* low level I/O file numbers */
-
- extern char actarget[20];
- extern char inline[80];
-
-
- int nprinter, logcopies;
-
-
- char *calloc(), *malloc();
-
-
- typedef struct dosfcb {
- char drive;
- char fname[8];
- char fext[3];
- unsigned curblk;
- unsigned recsize;
- long size;
- unsigned date;
- char reserved[10];
- char relrec;
- char record[4];
- } FCB;
-
- typedef struct exdirfcb {
- char dummy;
- char exset;
- char res[5];
- char flags;
- char drive;
- char fname[8];
- char fext[3];
- char gap[17];
- char size[4];
- } ExDirFCB;
-
- typedef struct exdosfcb {
- char dummy;
- char exset;
- char res[5];
- char flags;
- char drive;
- char fname[8];
- char fext[3];
- unsigned curblk;
- unsigned recsize;
- long size;
- unsigned date;
- char reserved[10];
- char relrec;
- char record[4];
- } ExFCB;
-
- extern char pathstring[256];
- extern char privmask;
-
- int _fmode = 0x8000;
-
-
-
- ExFCB sourcefile;
- ExFCB destfile;
-
-
-
- extern int curtrack,dstat,istat;
-
- extern int BrkFlag;
-
- struct fhead {
- char fflag;
- char fname[11];
- int boffset;
- int blklen;
- char data[1];
- };
-
- struct fcbstruct {
- char fcbdrive;
- char fcbname[11];
- int fblock;
- int recsize;
- unsigned fsizelow;
- unsigned fsizehigh;
- char reserved[12];
- char currec;
- char rndreclow[2];
- char rndrechigh[2];
- };
-
-
- char *dirhead = " DIRECTORY ";
- char twork[8208] ={0};
- char mname[13] = {0};
-
-
-
- abort()
- {
- cprintf("\r\n\7Restore session terminated.\r\n");
- /* if (printlog) {
- prnline();
- printstr("RESTORE SESSION CANCELLED\r\n");
- prnline();
- } */
- myexit(0);
- }
-
- myexit(exitcode)
- int exitcode;
- {
- /* if (printlog) {
- printstr("\r\n\r\n");
- prnline();
- printstr("END OF RESTORE LOG REPORT\r\n");
- prnline();
- }
- modLST(1); /* restore LST: to local and signal spooler to print */
- */ rewindtape();
- exit(exitcode);
- }
-
- /* FATAL ERROR REPORTING ROUTINE */
- error(message)
- char *message;
- {
- cprintf("FATAL ERROR: %s\7\r\n", message);
- /* if (printlog) {
- prnline();
- printstr("FATAL ERROR: "); printstr(message); printstr("\r\n");
- prnline();
- } */
- }
-
-
-
- rcheckbreak()
- {
- char ch;
-
- ChkKey();
- if (BrkFlag) {
- cprintf("\r\n\7");
- if (yes("Cancel Restore Session? (Y/N) ")) {
- abort();
- }
- }
- }
-
-
-
- char *msfname(name)
- char *name;
- {
- char *s1;
- int i;
-
- s1=mname;
- for (i=0;i<8;i++) {
- if (*name != ' ') *s1++ = *name++;
- else name++;
- }
- if (*name != ' ') *s1++='.';
- for (i=0;i<3;i++)
- if (*name != ' ') *s1++ = *name++;
- *s1 = 0;
- return (mname);
- }
-
-
-
- int readfile(buff,drive)
- struct fhead *buff;
- int drive;
- {
- struct fcbstruct fcb;
- char *s1,*s2;
- int i,ccode,wlen;
- int *reclow,*rechigh;
-
-
- reclow = (int *) fcb.rndreclow;
- rechigh = (int *) fcb.rndrechigh;
- s1=buff->fname;
- s2=fcb.fcbname;
- fcb.fcbdrive = drive;
- for (i=0;i<11;i++) *s2++=*s1++;
- if (buff->boffset) { /* Append To Split File */
- if (openfile(&fcb)) return(-1);
- }
- else if (makefile(&fcb)) return(-1);
- else FileAtt(&fcb,(buff->fflag) & ~LASTBIT);
- fcb.recsize=1;
- SetDTA(buff->data);
- rloop:
- *reclow = buff->boffset << 13;
- *rechigh = buff->boffset >> 3;
- if (buff->fflag & LASTBIT) {
- wlen = buff->blklen;
- if (!wlen) wlen = 0x2000;
- ccode =RBlkWrite(&fcb,wlen);
- closefile(&fcb);
- if (ccode) return (1); else return(0);
-
-
-
-
-
- }
- if (RBlkWrite(&fcb,0x2000)) {
- closefile(&fcb);
-
- return(1);
- }
- reread: ccode = readtape(buff);
- if (ccode==14) {
- if (curtrack < 3) {
- seltrack(curtrack+1);
- rewindtape();
- goto reread;
- }
- else {
- cprintf("\r\n\7File continues on another tape.\r\n");
- backmarks(1);
- closefile(&fcb);
- return(0);
- }
- }
- else if (ccode) {
- closefile(&fcb);
-
- return(1);
- }
- goto rloop;
- }
-
-
- skipfile(buff)
- char *buff;
- {
- int ccode;
- char *emask = "\20???????????????";
-
- skiploop:
- if (*buff & LASTBIT) return; /*last block */
- if (searchrec(buff,emask)) {
- if (curtrack == 3) {
- backmarks(1);
- return;
- }
- else {
- seltrack (curtrack+1);
- rewindtape();
- goto skiploop;
- }
- }
- }
- char npath[256] = {0};
-
- restoredir(buff,allfiles)
- char *buff;
- int allfiles;
- {
- char *s1,*s2,ch, *s;
- int drive,ccode,rflag,fileflag;
- int thandle;
-
-
- cprintf("Directory: ");
- cprintf(buff+80);
- cprintf("\r\non ");
- cprintf(buff+16);
- cprintf("\r\n");
-
- s = buff + 80;
- while (*s++) ; /* after loop *s is rights restored flag */
-
- if (allfiles) rflag = 1;
- else {
- if (!yes("Restore from this directory? (Y/N) ")) return;
- rflag = 0;
- while (!rflag) {
- cprintf("\r\n A: Restore to the same directory.\r\n");
- cprintf(" B: Restore to a different directory.\r\n");
- cprintf(" C: Restore to the default drive.\r\n\n");
- cprintf ("Select option: ");
- ch = getstr(inline,3);
- if (ch == 3) abort();
- ch = toupper(ch);
- cprintf("\r\n");
- if (ch == 'A') rflag = 1;
- else if (ch == 'B') rflag = 2;
- else if (ch == 'C') rflag = 3;
- }
- if (*s == 0xFF) restorerights = yes (
- "Do you wish to restore security information for this directory? (Y/N) ");
- else restorerights = FALSE;
- }
- if (rflag == 1) {
- drive = '^' - 'A' + 1;
- if (NewTemp(drive-1,0,buff+80,&thandle)) {
- if (allfiles) {
- if (MakeDir(drive-1,0,buff+80,&thandle)) {
- if (yes("\7Unable to make directory. Abort? (Y/N) "))
- abort();
- else return;
- }
- }
- else {
- cprintf("\7Unable to map to the directory.\r\n");
- if (yes("Do you wish to create it? (Y/N) ")) {
- if (MakeDir(drive-1,0,buff+80,&thandle)) {
- cprintf("Unable to make directory.\r\n");
- if (yes("Try a new destination? (Y/N) "))
- rflag = 2;
- else return;
- }
- }
- }
- }
- }
- if (rflag == 2) {
- drive = '^' - 'A' + 1;
- do {
- cprintf("Enter the destination directory: ");
- ch = getstr(npath,255);
- if (ch==3) abort();
- cprintf("\r\n");
- if (ccode = NewTemp(drive-1,0,npath,&thandle)) {
- cprintf("\7Unable to map to the directory.\r\n");
- if (yes("Do you wish to create it? (Y/N) ")) {
- ccode = MakeDir(drive-1,0,npath,&thandle);
- if (ccode)
- cprintf("\7Unable to make the directory");
- }
- }
- } while (ccode);
- }
- else if (rflag == 3) drive = 0;
- if (!allfiles)
- allfiles = yes("Restore all files in this directory? (Y/N) ");
-
- if (restorerights && (*s == 0xFF)) rrestore (drive-1,s+1);
-
- fileflag = TRUE;
- while (TRUE) {
- rcheckbreak();
- ccode=readtape(buff);
- if (ccode==14) { /* File Mark Detected */
- ccode=skiprecs(1);
- if (ccode==0) {
- backmarks(1);
- return;
- }
- if (curtrack ==3) {
- backmarks(2);
- return;
- }
- seltrack(curtrack+1);
- rewindtape();
- }
- else {
- cprintf("File ");
- cprintf(msfname(buff+1));
- if (allfiles) cprintf("\r\n");
- else {
- if (yes(" Restore? (Y/N) ")) fileflag = TRUE;
- else fileflag = FALSE;
- }
- if (fileflag) {
- if (ccode = readfile(buff,drive)) {
- if (ccode == -1) {
- cprintf("Unable to open file.\r\n");
- skipfile(buff);
- }
- else {
- cprintf("Error Restoring File.\r\n");
- return;
- }
- }
- }
- else skipfile(buff);
- }
- }
- }
-
-
- int searchhead(buff)
- char *buff;
- {
- char *s1,*s2;
- int i;
-
- nexttrack:
- if (skipmarks(2)) return (-1);
- backmarks(1);
- if (backrecs(1)) {
- if (curtrack < 3) {
- seltrack(curtrack+1);
- rewindtape();
- goto nexttrack;
- }
- else {
- rewindtape();
- return(1);
- }
- }
- if (readtape(buff)) return (-1);
- s1=buff; s2=dirhead;
- for (i=0;i<16;i++) if (*s1++ != *s2++) return(-1);
- skipmarks(1);
- return(0);
- }
-
- tapesetup(buff)
- char *buff;
- {
- char ch;
-
-
- newtape:
- rewindtape();
- cprintf(
- "Prepare tape in the Alloy unit and press any key to continue.\7\r\n");
- ch = getch();
- if (ch == 0x03) myexit();
-
- if (checkheader(buff)) {
-
- cprintf("Non Novell Tape\r\n");
- goto newtape;
-
- }
- }
-
-
- main() {
-
- int ccode,allfiles;
-
- trapbreak();
- nexttape:
- tapesetup(twork);
- allfiles = yes("Restore tape without queries? (Y/N) ");
- if (allfiles) {
- restorerights = yes (
- "Do you wish to restore security information from this tape? (Y/N) ");
- if (restorerights) {
- cprintf (
- "WARNING: To guarantee proper restoration of directory rights, trustee lists,\r\n");
- cprintf (
- "and file flags, you should be logged in as the real SUPERVISOR user. This is\r\n");
- cprintf (
- "especially true if you are going to do a full system restore. If you are not\r\n");
- cprintf (
- "logged in as the SUPERVISOR, press ^C at the next question to exit.\r\n\r\n");
- }
- cprintf(
- "This will restore the entire tape, replacing all files without stopping.\r\n");
- if (!yes("Do you wish to continue? (Y/N) ")) goto nexttape;
- }
- while(TRUE) {
- ccode = searchhead(twork);
- if (ccode==1) {
- cprintf("End of tape found.\r\n");
- if (yes("Do you want to continue to a new tape? (Y/N) "))
- goto nexttape;
- exit(0);
- }
- if (ccode) {
- cprintf("Invalid tape format encountered.\r\n");
- goto nexttape;
- }
- restoredir(twork,allfiles);
- }
-
- }